package impl

import (
	"fmt"
	"github.com/starmotioncf/soutchatinternal"
	"github.com/starmotioncf/soutchatinternal/dto"
	"github.com/starmotioncf/soutchatinternal/service"
	"github.com/starmotioncf/soutchatpkg/storage"
	"time"

	"github.com/gin-gonic/gin"
)

type commonService struct {
	*service.Service
	fs *storage.Storage
}

func NewCommonService(s *service.Service, fs *storage.Storage) service.CommonService {
	return &commonService{
		Service: s,
		fs:      fs,
	}
}

func (s *commonService) GetPresignURL(ctx *gin.Context, req *dto.PresignUrlReq) (url string, err error) {
	uploadKey := fmt.Sprintf("%d-%d", internal.GetUidFromCtx(ctx), time.Now().Unix())
	return s.fs.GetPresignedURL(ctx, req.Bucket, uploadKey, time.Minute*5)
}
